<extend name="Public/base" />
<block name="body">
    <div class="main-title">
        <h2>商品详情</h2>
    </div>

    <div class="cf">
        <div class="tools auth-botton">
            <a id="add-group" class="btn" href="{:U('createProduct')}">新 增</a>
            <a url="{:U('changestatus',array('method'=>'resume'))}" class="btn ajax-post" target-form="ids" >启 用</a>
            <a url="{:U('changestatus',array('method'=>'forbid'))}" class="btn ajax-post" target-form="ids" >禁 用</a>
            <a url="{:U('changestatus',array('method'=>'delete'))}" class="btn ajax-post confirm" target-form="ids" >删 除</a>
        </div>

        <!-- 高级搜索 -->
        <div class="search-form fr cf">
            <div class="sleft">
                <input type="text" name="name" class="search-input" value="{:I('name')}" placeholder="请输入商品名称">
                <a class="sch-btn" href="javascript:;" id="search" url="{:U('index')}"><i class="btn-search"></i></a>
            </div>
        </div>
    </div>
    <!-- 数据列表 -->
    <div class="data-table table-striped">
        <table class="">
            <thead>
            <tr>
                <th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>

                <th class="">商品编号</th>
                <th class="">商品分类</th>
                <th class="">商品名称</th>
                <th class="">状态</th>
                <th class="">操作</th>
            </tr>
            </thead>
            <tbody>
            <notempty name="_list">
                <volist name="_list" id="vo">
                    <tr>
                        <td><input class="ids" type="checkbox" name="id[]" value="{$vo.id}" /></td>
                        <td><a href="{:U('Product/editproduct?id='.$vo['id'])}">{$vo.spu}</a> </td>
                        <td>{$vo.classname}</td>
                        <td>{$vo.name}</td>
                        <td>{$vo.status_text}</td>
                        <td><eq name="vo.status" value="1">
                            <a href="{:U('Product/changeStatus?method=forbid&id='.$vo['id'])}" class="ajax-get">禁用</a>
                            <else/>
                            <a href="{:U('Product/changeStatus?method=resume&id='.$vo['id'])}" class="ajax-get">启用</a>
                        </eq>
                            <a href="{:U('Product/changeStatus?method=delete'.$vo['id'])}" class="confirm ajax-get">删除</a>
                            <a  href="{:U('Product/applypurchase?id='.$vo['id'])}"   >申请采购</a>
                            <a data-pid="{$vo.id}" data-pname="{$vo.name}"  class=" applypurchase">申请采购</a>
                        </td>
                    </tr>
                </volist>
                <else/>
                <td colspan="6" class="text-center"> aOh! 暂时还没有内容! </td>
            </notempty>
            </tbody>
        </table>

    </div>
    <div class="page">
        {$_page}
    </div>
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel">商品申购</h4>
                </div>
                <div class="modal-body">
                    <form action="{:U('Product/applypurchase')}" id="applyform" method="post">
                        <div class="form-group">
                            <label for="proName" class="control-label">商品:</label>
                            <input type="text" class="form-control" id="proName" name="proName">
                            <input type="hidden"  id="pid" name="pid">
                        </div>
                        <div class="form-group row form-inline">
                            <div class=" input-group col-md-3 col-sm-3" style="margin-left: 16px;">
                                <input id="jin" type="text" name="jin" class="form-control input-small" value="" placeholder=""/><div class="input-group-addon">斤</div>
                            </div>
                            <div class="input-group col-md-3 col-sm-3" >
                                <input id="head" type="text" name="head" class="form-control input-small " value="" placeholder="" /><div class="input-group-addon">头</div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="num" class="control-label">数量:</label>
                            <input id="num" type="text" name="num" class="form-control"  required/>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" id="submitbtn" class="btn btn-primary">确认</button>
                </div>
            </div>
        </div>
    </div>
</block>

<block name="script">

    <script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>

    <script type="text/javascript">
        $(function(){
            $("#action_add").click(function(){
                window.location.href = $(this).attr('url');
            });
            $(".applypurchase").click(function(){
                var pid = $(this).data('pid');
                var pname = $(this).data('pname');
                $("#pid").val(pid);
                $("#proName").val(pname);
                $("#jin").val();
                $("#head").val();
                $("#myModal").modal();
            });
            $("#submitbtn").click(function(){
                $("#applyform").submit();
            })
        });
        //搜索功能
        $("#search").click(function(){
            var url = $(this).attr('url');
            var query  = $('.search-form').find('input').serialize();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
            query = query.replace(/^&/g,'');
            if( url.indexOf('?')>0 ){
                url += '&' + query;
            }else{
                url += '?' + query;
            }
            window.location.href = url;
        });
        //回车搜索
        $(".search-input").keyup(function(e){
            if(e.keyCode === 13){
                $("#search").click();
                return false;
            }
        });

       //导航高亮
       highlight_subnav('{:U('Product/index')}');
   </script>
</block>